﻿
    using Maticsoft.BLL;
    using Maticsoft.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Text;
    using System.Web;
    using System.Web.UI.HtmlControls;

    public partial class WebPage_YingXiao_ShujuXiazai_Team : MarketBBasePage
    {
        public Maticsoft.BLL.orderdetail detailbll = new Maticsoft.BLL.orderdetail();
        public List<Maticsoft.Model.orderdetail> detaillist = new List<Maticsoft.Model.orderdetail>();

        public int j = 0;
        public Maticsoft.Model.orderdetail orderModel = new Maticsoft.Model.orderdetail();
        public Maticsoft.BLL.Team teambll = new Maticsoft.BLL.Team();
        public Maticsoft.Model.Team teamModel = new Maticsoft.Model.Team();


        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "yingxiao";
            this.YingXiao1.Select = "shuju";
            if (base.Request.HttpMethod == "POST")
            {
                if (((base.Request.Form["state[]"] != null) && (base.Request.Form["service[]"] != null)) && (base.Request["receive"] != null))
                {
                    string teamid = "";
                    if ((base.Request.Form["team_id"] != null) && (base.Request.Form["team_id"].ToString() != ""))
                    {
                        teamid = base.Request.Form["team_id"].ToString();
                    }
                    else
                    {
                        teamid = "0";
                    }
                    string state = base.Request.Form["state[]"].ToString();
                    string service = base.Request.Form["service[]"].ToString();
                    string receive = base.Request.Form["receive"].ToString();
                    this.xiazai(teamid, state, service, receive);
                }
                else
                {
                    this.SetError("-ERR ERR_NO_DATA");
                    base.Response.Redirect("YingXiao_ShujuXiazai_Team.aspx");
                }
            }
        }

        private void xiazai(string teamid, string state, string service, string receive)
        {
            StringBuilder builder = new StringBuilder();
            if (((state == "") || (service == "")) || (receive == ""))
            {
                this.SetError("-ERR ERR_NO_DATA");
                base.Response.Redirect("YingXiao_ShujuXiazai_Team.aspx");
            }
            else
            {
                int num;
                builder.Append("<html>");
                builder.Append("<meta http-equiv=content-type content=\"text/html; charset=UTF-8\">");
                builder.Append("<body><table border='1'>");
                builder.Append("<tr>");
                builder.Append("<td>ID</td>");
                builder.Append("<td align='left'>订单号</td>");
                builder.Append("<td>支付号</td>");
                builder.Append("<td>支付方式</td>");
                builder.Append("<td>单价</td>");
                builder.Append("<td>数量</td>");
                builder.Append("<td>运费</td>");
                builder.Append("<td>总金额</td>");
                builder.Append("<td>支付款</td>");
                builder.Append("<td>余额付款</td>");
                builder.Append("<td>支付状态</td>");
                builder.Append("<td>支付日期</td>");
                builder.Append("<td>备注</td>");
                builder.Append("<td>快递信息</td>");
                builder.Append("<td>用户名</td>");
                builder.Append("<td>用户邮箱</td>");
                builder.Append("<td>用户手机</td>");
                builder.Append("<td>收件人</td>");
                builder.Append("<td>手机号码</td>");
                builder.Append("<td>邮政编码</td>");
                builder.Append("<td>送货地址</td>");
                builder.Append("</tr>");
                string strWhere = " 1=1  ";
                string[] strArray = state.Split(new char[] { ',' });
                string str2 = "";
                bool flag = false;
                for (num = 0; num < strArray.Length; num++)
                {
                    str2 = str2 + "'" + strArray[num] + "',";
                    if (strArray[num] == "unpay")
                    {
                        flag = true;
                    }
                }
                str2 = str2.Substring(0, str2.Length - 1);
                strWhere = strWhere + " and State in ( " + str2 + " )";
                string[] strArray2 = receive.Split(new char[] { ',' });
                string str3 = "";
                for (num = 0; num < strArray2.Length; num++)
                {
                    if (strArray2.Length == 1)
                    {
                        if (strArray2[num] == "0")
                        {
                            str3 = " and Express_id=0";
                        }
                        else
                        {
                            str3 = " and Express_id>0";
                        }
                        break;
                    }
                    if (strArray2.Length == 2)
                    {
                        str3 = " and (Express_id=0 or Express_id>0)";
                        break;
                    }
                }
                strWhere = strWhere + str3;
                if (!flag)
                {
                    string[] strArray3 = service.Split(new char[] { ',' });
                    string str4 = "";
                    for (num = 0; num < strArray3.Length; num++)
                    {
                        str4 = str4 + "'" + strArray3[num] + "',";
                    }
                    str4 = str4.Substring(0, str4.Length - 1);
                    strWhere = strWhere + " and [Service] in ( " + str4 + " )";
                }
                Maticsoft.BLL.Order order = new Maticsoft.BLL.Order();
                strWhere = strWhere + " and (Convert(varchar(10),Create_time,20)>='" + base.Request["txtstart"] + "' and Convert(varchar(10),Create_time,20)<='" + base.Request["txtend"] + "')";
                DataSet set = order.GetList(strWhere);
                if (set.Tables[0].Rows.Count > 0)
                {
                    for (num = 0; num < set.Tables[0].Rows.Count; num++)
                    {
                        StringBuilder builder2;
                        DataRow row = set.Tables[0].Rows[num];
                        Maticsoft.BLL.orderdetail orderdetail = new Maticsoft.BLL.orderdetail();
                        List<Maticsoft.Model.orderdetail> modelList = new List<Maticsoft.Model.orderdetail>();
                        modelList = orderdetail.GetModelList("Order_id=" + row["Id"].ToString());
                        if (modelList.Count > 0)
                        {
                            int num4;
                            int num2 = 0;
                            builder2 = new StringBuilder();
                            foreach (Maticsoft.Model.orderdetail orderdetail2 in modelList)
                            {
                                if (teamid != "0")
                                {
                                    num4 = int.Parse(teamid);
                                    if (num4 == orderdetail2.Teamid)
                                    {
                                        num2++;
                                        builder2.Append(num2 + "、");
                                        this.teamModel = this.teambll.GetModel(Convert.ToInt32(orderdetail2.Teamid));
                                        if (this.teamModel != null)
                                        {
                                            builder2.Append("项目" + this.teamModel.Id.ToString() + "：" + this.teamModel.Title);
                                        }
                                        else
                                        {
                                            builder2.Append("");
                                        }
                                        builder2.Append("<br>");
                                    }
                                }
                                else
                                {
                                    num2++;
                                    builder2.Append(num2 + "、");
                                    this.teamModel = this.teambll.GetModel(Convert.ToInt32(orderdetail2.Teamid));
                                    if (this.teamModel != null)
                                    {
                                        builder2.Append("项目" + this.teamModel.Id.ToString() + "：" + this.teamModel.Title);
                                    }
                                    else
                                    {
                                        builder2.Append("");
                                    }
                                    builder2.Append("<br>");
                                }
                            }
                            if (builder2.ToString() == "")
                            {
                                goto Label_0ED6;
                            }
                            builder.Append("<tr>");
                            num4 = this.j + 1;
                            builder.Append("<td>" + num4.ToString() + "</td>");
                            builder.Append("<td>");
                            builder.Append(row["ID"].ToString() + "&nbsp;&nbsp;&nbsp;<br>");
                            builder.Append(builder2);
                            builder.Append("</td>");
                        }
                        else
                        {
                            builder2 = new StringBuilder();
                            if (teamid != "0")
                            {
                                if (teamid == row["Team_id"].ToString())
                                {
                                    builder2.Append("<td>");
                                    builder2.Append(row["ID"].ToString());
                                    this.teamModel = this.teambll.GetModel(int.Parse(row["Team_id"].ToString()));
                                    if (this.teamModel != null)
                                    {
                                        builder2.Append(string.Concat(new object[] { "&nbsp;项目", this.teamModel.Id, ":&nbsp;", this.teamModel.Title }));
                                    }
                                    builder2.Append("</td>");
                                }
                            }
                            else
                            {
                                builder2.Append("<td>");
                                builder2.Append(row["ID"].ToString());
                                this.teamModel = this.teambll.GetModel(int.Parse(row["Team_id"].ToString()));
                                if (this.teamModel != null)
                                {
                                    builder2.Append(string.Concat(new object[] { "&nbsp;项目", this.teamModel.Id, ":&nbsp;", this.teamModel.Title }));
                                }
                                builder2.Append("</td>");
                            }
                            if (builder2.ToString() == "")
                            {
                                goto Label_0ED6;
                            }
                            builder.Append("<tr>");
                            builder.Append("<td>" + ((this.j + 1)).ToString() + "</td>");
                            builder.Append(builder2);
                        }
                        builder.Append("<td>" + row["Pay_id"].ToString() + "</td>");
                        switch (row["Service"].ToString())
                        {
                            case "yeepay":
                                builder.Append("<td>易宝</td>");
                                break;

                            case "alipay":
                                builder.Append("<td>支付宝</td>");
                                break;

                            case "tenpay":
                                builder.Append("<td>财付通</td>");
                                break;

                            case "chinabank":
                                builder.Append("<td>网银在线</td>");
                                break;

                            case "credit":
                                builder.Append("<td>余额付款</td>");
                                break;

                            case "cash":
                                builder.Append("<td>线下支付</td>");
                                break;

                            default:
                                builder.Append("<td></td>");
                                break;
                        }
                        builder.Append("<td>" + row["Price"].ToString() + "</td>");
                        builder.Append("<td>");
                        builder.Append("购买了" + row["Quantity"].ToString() + "件");
                        int num3 = 1;
                        modelList = orderdetail.GetModelList("Order_id=" + row["Id"].ToString());
                        if (modelList.Count > 0)
                        {
                            builder.Append("(");
                            foreach (Maticsoft.Model.orderdetail orderdetail3 in modelList)
                            {
                                builder.Append(string.Concat(new object[] { num3, ".项目", orderdetail3.Teamid, ":购买", orderdetail3.Num, "件&nbsp;" }));
                                num3++;
                            }
                            builder.Append(")");
                        }
                        builder.Append("</td>");
                        builder.Append("<td>" + row["Fare"].ToString() + "</td>");
                        builder.Append("<td>" + row["Origin"].ToString() + "</td>");
                        builder.Append("<td>" + row["Money"].ToString() + "</td>");
                        builder.Append("<td>" + row["Credit"].ToString() + "</td>");
                        if (row["State"].ToString() == "pay")
                        {
                            builder.Append("<td>已支付</td>");
                        }
                        if (row["State"].ToString() == "unpay")
                        {
                            builder.Append("<td>未支付</td>");
                        }
                        builder.Append("<td>" + row["Pay_time"].ToString() + "</td>");
                        builder.Append("<td>" + row["Remark"] + "</td>");
                        Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
                        string str5 = "";
                        if (int.Parse(row["Express_id"].ToString()) != 0)
                        {
                            Maticsoft.Model.Category category2 = category.GetModel(int.Parse(row["Express_id"].ToString()));
                            if (category2 != null)
                            {
                                str5 = category2.Name + ":";
                                builder.Append(string.Concat(new object[] { "<td>", str5, row["Express_no"], "</td>" }));
                            }
                            else
                            {
                                builder.Append("<td>&nbsp;</td>");
                            }
                        }
                        else
                        {
                            builder.Append("<td>&nbsp;</td>");
                        }
                        Maticsoft.Model.UserInfo model = new Maticsoft.BLL.UserInfo().GetModel(int.Parse(row["User_id"].ToString()));
                        if (model != null)
                        {
                            builder.Append("<td>" + model.Username + "</td>");
                            builder.Append("<td>" + model.Email + "</td>");
                            builder.Append("<td>" + model.Mobile + "</td>");
                        }
                        else
                        {
                            builder.Append("<td></td>");
                            builder.Append("<td></td>");
                            builder.Append("<td></td>");
                        }
                        builder.Append("<td>" + row["Realname"] + "</td>");
                        builder.Append("<td>" + row["Mobile"] + "</td>");
                        builder.Append("<td>" + row["Zipcode"] + "</td>");
                        builder.Append("<td>" + row["Address"] + "</td>");
                        builder.Append("</tr>");
                        this.j++;
                    Label_0ED6: ;
                    }
                }
                builder.Append("</table></body></html>");
                base.Response.ClearHeaders();
                base.Response.Clear();
                base.Response.Expires = 0;
                base.Response.Buffer = true;
                base.Response.AddHeader("Accept-Language", "zh-tw");
                base.Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode("team_" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls", Encoding.UTF8));
                base.Response.ContentType = "Application/octet-stream";
                base.Response.Write(builder.ToString());
                base.Response.End();
            }
        }
    }


